1. yum安装

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.  

以下全部引用自:
Redhat7中yum安装以及问题解决办法(YUM和wget都无法使用的情况下)

解决:

1. 检查系统环境

1
cat /etc/redhat-release

2. 检查yum包安装情况

1
rpm -qa |grep yum

3. 绝对不能先删除系统自带的yum包

4. 先安装wget

yum安装不上就只能手动下载传上去了

5. 删除系统自带的yum包

1
2
rpm -qa|grep yum|xargs rpm -e --nodeps(不检查依赖,直接删除rpm包)  
rpm -qa |grep yum (查询确认)

6. 下载yum安装包

下载地址:Index of /centos/7/os/x86_64/Packages/

1
2
3
4
5
6
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm  
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-158.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-45.el7.noarch.rpm

7. 安装yum包

无视冲突强行安装

1
2
3
--force 即使覆盖属于其它包的文件也强迫安装  
--nodeps 如果该RPM包的安装依赖其它包,即使其它包没装,也强迫安装。
rpm -ivh --force --nodeps yum* 最终的强制安装指令

8. 配置163源

1
yum-config-manager --add-repo="http://mirrors.163.com/.help/CentOS6-Base-163.repo"

Linux vi全局替换方法

1
2
3
4
5
cd /etc/yum.repos.d/

更改文件中的“$releasever”为“7”,“RPM-GPG-KEY-CentOS-6”为“RPM-GPG-KEY-CentOS-7”
:%s/$releasever/7/ge
:%s/RPM-GPG-KEY-CentOS-6/RPM-GPG-KEY-CentOS-7/ge

更改后文件示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#CentOS-Base.repo  
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-7 - Base - 163.com
baseurl=http://mirrors.163.com/centos/7/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-7 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/7/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-7 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/7/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-7 - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/7/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

9. 清除缓存

1
2
clean all   #清理yum缓存,使设置生效  
yum makecache #将服务器上的软件包信息缓存到本地,以提高搜索安装软件的速度

2. Docker CE 安装

以下全部引用自:
Centos7 安装 Docker-CE 社区版

1. 安装依赖

1
yum install -y yum-utils device-mapper-persistent-data lvm2

2. 配置镜像库

1
2
3
4
> yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
> yum-config-manager --enable docker-ce-edge

也可改为国内镜像

1
2
3
yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

若要禁止edge版本

1
yum-config-manager --disable docker-ce-edge

3. 删除老版本docker

1
2
3
4
5
6
7
8
9
10
> yum list docker

Installed Packages
docker.x86_64 2:1.12.6-28.git1398f24.el7.centos @extras
> sudo yum erase docker.x86_64
Removed:
docker.x86_64 2:1.12.6-28.git1398f24.el7.centos
> sudo yum list container-selinux-2.12-2.gite7096ce.el7.noarch

> sudo yum erase container-selinux.noarch
1
2
3
4
5
6
7
8
9
10
11
> yum list installed | grep docker
docker-client.x86_64 2:1.12.6-28.git1398f24.el7.centos
docker-common.x86_64 2:1.12.6-28.git1398f24.el7.centos
> sudo yum erase -y docker-client.x86_64
> sudo yum erase -y docker-common.x86_64

> sudo yum remove docker \
docker-common \
container-selinux \
docker-selinux \
docker-engine

4. 安装docker

1
2
3
> sudo yum makecache fast

> sudo yum install docker-ce

如果生产系统需要稳定版本, 需要yum list进行查询. 但yum list只会显示二进制包, 加上.x86_64会显示包含源码包的全部的包。sort -r会按版本倒序排序.

1
2
3
4
5
6
7
8
9
10
> yum list docker-ce.x86_64  --showduplicates |sort -r
* updates: mirrors.tuna.tsinghua.edu.cn
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, langpacks
* extras: mirror.bit.edu.cn
docker-ce.x86_64 17.05.0.ce-1.el7.centos docker-ce-edge
docker-ce.x86_64 17.04.0.ce-1.el7.centos docker-ce-edge
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
* base: mirror.bit.edu.cn

第二列是版本号. el7表示centos7. 第三列是库名.

安装指定版本: sudo yum install docker-ce-

1
2
3
4
5
6
7
8
> sudo yum install docker-ce-17.03.1.ce-1.el7.centos
Installed:
docker-ce.x86_64 0:17.03.1.ce-1.el7.centos

Dependency Installed:
docker-ce-selinux.noarch 0:17.05.0.ce-1.el7.centos

Complete!

5. 如果要删除

删除 docker-ce 版和镜像

1
2
> sudo yum remove docker-ce
> sudo rm -rf /var/lib/docker

6. 启动Docker

1
2
3
4
5
6
7
8
9
10
> sudo systemctl start docker
> docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

7. 非root用户使用docker

将需要使用 docker 的用户加入 docker 用户组

建立 docker 组:

1
$ sudo groupadd docker

将当前用户加入 docker 组:

1
$ sudo usermod -aG docker $USER

8. docker自启动与禁止

1
sudo systemctl enable docker

禁止自启动

1
sudo systemctl disable docker

3. node.js安装

1. 通过包管理器安装

通过包管理器安装 Node.js

NodeSource Node.js Binary Distributions

Run as root on RHEL, CentOS or Fedora:

1
curl --silent --location https://rpm.nodesource.com/setup | bash -

Then install, as root:

1
yum -y install nodejs

Optional: install build tools

To compile and install native addons from npm you may also need to install build tools:

1
2
yum install gcc-c++ make
# or: yum groupinstall 'Development Tools'

1
sudo yum install nodejs npm

2. 使用 nvm 安装

centos 使用 nvm 安装 nodejs

1. 安装 nvm

How to Install NVM (Node Version Manager) for Node.js on CentOS 7

安装最新版git

1
2
wget -qO- https://raw.githubusercontent.com/cnpm/nvm/master/install.sh | bash
# or: curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash

重启 shell ,输入 nvm --version 可以查看当前 nvm 的版本

2. 安装nodejs

nvm使用

1
nvm help

查看可安装版本

1
nvm ls-remote

安装

1
2
3
nvm install v4.6.0

node --version

查看当前已经安装的版本

1
nvm ls

切换版本

1
nvm use v4.6.0

设置默认版本

1
nvm alias default v4.6.0

4. linux删除工具

使用 Linux 安全删除工具

trash-cli - Command Line Interface to FreeDesktop.org Trash
防止误删文件

1. 安装

1
2
easy_install trash-cli
#or: yum install -y trash-cli
1
2
3
4
5
6
7
8
9
10
11
From sources
System-wide installation:

git clone https://github.com/andreafrancia/trash-cli.git
cd trash-cli
sudo python setup.py install
User-only installation:

git clone https://github.com/andreafrancia/trash-cli.git
cd trash-cli
python setup.py install --user
1
Installed /usr/lib/python2.7/site-packages/trash_cli-0.17.1.14_r0-py2.7.egg

2. 替代 rm命令

Make “rm” Command To Move The Files To “Trash Can” Instead Of Removing Them Completely

1
2
3
4
//Create a alias on .bashrc file.
alias rm=”trash-put”

source ~/.bashrc

3. 命令

1
2
3
4
5
6
7
8
9
trash-put  xxx        将文件或目录移入回收站

trash-empty 清空回收站

trash-list 列出回收站中的文件

restore-trash 还原回收站中的文件

trash-rm xxx 删除回首站中的单个文件

5. ssh链接服务器

Connecting to a RedHat server with SSH

1
ssh -i "xxx.pem证书文件" 服务器地址

ssh: The authenticity of host ‘hostname’ can’t be established

使用ssh连接远程主机时加上-o StrictHostKeyChecking=no的选项,去掉对主机的验证检查

6. ssh链接github

以下引用自:
Centos 7 使用git 用 ssh 连接github服务器

生成ssh密钥

1
ssh-keygen -t rsa -C "邮箱地址"

1
cat id_rsa.pub

复制内容到github的SSH and GPG keys

测试能否链接

1
ssh -T git@github.com

ls后看到新增的known_hosts文件

7. Linux后台命令 nohup

Linux nohup用法

linux后台执行命令:&和nohup

nohup不挂起( no hang up)

1
nohup command &

nohup成功后还需要按终端上键盘任意键退回到shell输入命令窗口,然后通过在shell中输入exit来退出终端。

jobs查看在后台运行的命令,jobs -l查看pid。

8. 查询端口号占用并清除

1
lsof -i:80
1
kill pid